function main() {
    debugger;
    const self = this;
    let pageRenderElement = self.$$root().$parent.$parent.$parent;
    const formPartEle = self.findElement("form_part_3d8hdo");
    const formRenderEle = formPartEle.$$getRenderElement();

    if (!formRenderEle) {
        console.error("Form render element not found.");
        return;
    }

    const unitId = self.$$("number_input_fg3j6z") && self.$$("number_input_fg3j6z").cValue;

    if (unitId === null || unitId === undefined || unitId === '') {
        let query = self.$route.query;
        if (query && query.unitId) {
            self.$$("number_input_fg3j6z").$$setValue(query.unitId);
        } else {
            self.$message.error("当前机构有误！");
            return;
        }
    }

    formRenderEle.onSave().then((res) => {
        if (!res || !res.result) {
            console.error("No result from form save.");
            return;
        }

        const lawCheckUnitCheckMatterDomainInfoList = self.$$("tree_multiple_select_fo6f25").cValue;    // 事项领域 domianId
        const lawUnitMatterRelLitigantTypeList = self.$$("multiple_select_dcgyfx").cValue;              // 检查对象
        const lawCheckUnitRelMatterExtendInfoList = self.$$("single_select_b68roc").cValue;         // 检查方式

        const unitId = self.$$("number_input_fg3j6z").cValue;                                       // 机构标识
        const matterId = res.result.documentNo; // 事项标识

        const result = {
            unitId: unitId,
            matterId: matterId,
            lawCheckUnitCheckMatterDomainInfoList: lawCheckUnitCheckMatterDomainInfoList,
            lawUnitMatterRelLitigantTypeList: lawUnitMatterRelLitigantTypeList,
            lawCheckUnitRelMatterExtendInfoList: [lawCheckUnitRelMatterExtendInfoList],
            unitMatterRelUpdateFlag: 1
        };
        let jsonString = JSON.stringify(result);
        insertUnitMatter(jsonString).then(() => {

            pageRenderElement.goHistory(-1);
        })

        console.log("Processed Data:", result);
    }).catch((error) => {
        console.error("Error saving form:", error);
    });
}

function insertUnitMatter(jsonString) {
    return new Promise((resolve, reject) => {
        // "ds_api:819c6be7-a6db-4d68-a401-54fa70f94d24"
        api.DATA_SOURCE_EXECUTE("ds_api:819c6be7-a6db-4d68-a401-54fa70f94d24", "api", [], [], jsonString).then(res => {
            console.log(res);
            resolve(res);
        });
    });

}
